package com.rzjm.api.netty.water.handler;

import com.rzjm.api.netty.water.MessageHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class MessageReceiverHandler extends ChannelInboundHandlerAdapter {
    private final Logger LOGGER = LoggerFactory.getLogger(MessageReceiverHandler.class);


    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) {
        if (msg == null) {
            LOGGER.error("=======>receive message is null");
        }else if (msg instanceof String) {
            MessageHandler.messageHandler(ctx, (String)msg);
        } else {
            LOGGER.error("=======>not support receive message type : {}", msg.getClass().getSimpleName());
        }
        ctx.fireChannelRead(msg);
    }
}
